package cn.animal; 

import java.util.ArrayList; 

import java.util.List; 

public class ZooPeopleCollection implements ManDataAccess{ 

protected List<ZooPeople> peopleList; 

public ZooPeopleCollection(){ 

peopleList = new ArrayList<ZooPeople>(); 

} 

public ZooPeopleCollection(List<ZooPeople> peopleList){ 

this.peopleList = peopleList; 

} 

@Override 

public boolean addPeople(ZooPeople zooPeople) { 

return this.peopleList.add(zooPeople); 

} 

@Override 

public boolean deletePeople(ZooPeople zooPeople) { 

return this.peopleList.remove(zooPeople); 

} 

@Override 

public boolean deletePeople(String zoopeopleName) { 

return deletePeople(findPeople(zoopeopleName)); 

} 

@Override 

public boolean updatePeople(ZooPeople oldPeople, ZooPeople newPeople) { 

boolean updatePeopleSucessed = false; 

if (oldPeople == findPeople(oldPeople.getzooPeopleName())){ 

if(deletePeople(oldPeople)){ 

updatePeopleSucessed = addPeople(newPeople); 

} 

} 

return updatePeopleSucessed; 

} 

@Override 

public ZooPeople findPeople(String zooPeopleName) { 

ZooPeople foundPeople = null; 

for(ZooPeople current:this.peopleList){ 

if(current.getzooPeopleName().equals(zooPeopleName)){ 

foundPeople =current; 

} 

} 

return foundPeople; 

} 

public String displayAllPeople(){ 

String displayStr = ""; 

for (ZooPeople currentPeople:this.peopleList){ 

displayStr += currentPeople.getzooPeopleName(); 

} 

return displayStr; 

} 

}